import React from 'react'
import {Row, Col, Card, message} from 'antd'
import {LeftOutlined} from '@ant-design/icons';
import '../styles.css'
import api from "../../../api/api";
import axios from "axios";


class EmployeeDetail extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            title: "新增公司",
            uName:"",
            uPwd:"",
            detailHidden: true,
            param:{
                name:"",
                gender:"",
                phone:"",
                email:"",
                idcard:"",
                username:"",
                userpassword:"",
                entrytime:""
            },
        };
    }

    componentDidMount() {
        console.log("初始化");
        this.props.onRef2('EmployeeDetail', this)
    }


    //获取用户名和密码
    //查看详情
    getMeassage(item) {
        console.info("查看详情===", item);
        let that = this;
        let username1 = "";
        let userpwd1 = "";
        if(item.userinfoId!=null) {
            axios.post(api.api_URL + "/employee/getUserInfoUnameAndUpwdByUid?id=" + item.id, {
                "userinfoId": item.userinfoId
            }, {
                header: {
                    "Content_Type": api.ContentType
                }
            }).then(function (res) {
                console.info(res.data.object.uname)
                console.info(res.data.object.upwd)
                //that.handleCancel()
                username1 = res.data.object.uname
                userpwd1 = res.data.object.upwd
                if (res.data.errorCode == 1) {

                    message.success({content: "用户名密码查询成功！"})
                } else {
                    message.error({content: "用户名密码查询失败！"})
                }
                that.setState({
                    detailHidden: false,

                    param: {
                        name: item.uinfoName,
                        gender: item.uinfoGender,
                        phone: item.uinfoPhone,
                        email: item.uinfoEmail,
                        idcard: item.uinfoIdcard,
                        entrytime: item.createTime,
                        username: username1,
                        userpassword: userpwd1
                    }

                })
            }).catch(function (err) {
                console.log(err);
            });
        }else{
            that.setState({
                detailHidden: false,
                param: {
                    name: item.uinfoName,
                    gender: item.uinfoGender,
                    phone: item.uinfoPhone,
                    email: item.uinfoEmail,
                    idcard: item.uinfoIdcard,
                    entrytime: item.createTime,
                    username: "还没有为员工申请账号密码",
                    userpassword: "还没有为员工申请账号密码"
                }

            })
        }
    }

        onClickReturnMain = e => {
        this.props.returnMain()
            this.setState({},() => {
                this.clearData()
            });
        }


    returnMain = e => {
        this.setState({
            detailHidden: true
        })
    }

    onRef = (ref) => {
        this.child = ref

    }

    onRef2=(name,ref) => {
        switch (name) {
            case 'EmployeeDetail':
                this.detail = ref
                break
        }
    }
    //清除数据
    clearData() {
        this.setState({
            param: {
                name: "",
                gender: "",
                phone: "",
                email: "",
                idcard: "",
                username: "",
                userpassword: "",
                entrytime: ""
            }
        })
    }
    //获取设置的用户名
    getusername(e){
        console.log(e.target.value)
        this.setState({
            uName:e.target.value,
            param:{
                username:e.target.value
            }
        })
    }

    //获取设置的密码
    getpassword=(e)=>{
        console.log(e.target.value)
        this.setState({
            uPwd:e.target.value,
            param:{
                userpassword:e.target.value
            }
        })
    }
    render() {
        return (
            <div className="girdBg">
                <Row className="searchBox">
                    <Col>
                        {/*返回上一级页面*/}
                        <div className="returnBtn" onClick={this.onClickReturnMain}>
                            <LeftOutlined/>
                        </div>
                    </Col>
                </Row>
                <Row className="searchBox">
                    <Col span={24}>
                        <Card title="员工信息表" bordered={false}>
                            <p>
                                <span>姓名:</span>
                                <span>{this.state.param.name}</span>
                            </p>
                            <p>
                                <span>性别:</span>
                                <span>{this.state.param.gender}</span>
                            </p>
                            <p>
                                <span>身份证号码:</span>
                                <span>{this.state.param.idcard}</span>
                            </p>
                            <p>
                                <span>手机号:</span>
                                <span>{this.state.param.phone}</span>
                            </p>
                            <p>
                                <span>邮箱:</span>
                                <span>{this.state.param.email}</span>
                            </p>
                            <p>
                                <span>入职时间:</span>
                                <span>{this.state.param.entrytime}</span>
                            </p>
                            <p>
                                <span>账号:</span>
                                <span>{this.state.param.username}</span>
                            </p>
                            <p>
                                <span>密码:</span>
                                <span>{this.state.param.userpassword}</span>
                            </p>
                        </Card>
                    </Col>
                </Row>
            </div>
        )
    }
}

export default EmployeeDetail
